package servlet;

import service.BookingService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "UpdateServlet", value = "/UpdateServlet")
public class UpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        BookingService service = new BookingService();
        int status;
        status = Integer.parseInt(request.getParameter("status"));
        int id;
        id = Integer.parseInt(request.getParameter("id"));
        int relust = service.update(status,id);
        HttpSession session = request.getSession();
        session.setMaxInactiveInterval(0);
        String info = "";
        if (relust > 0) {
            if (status == 1) {
                info = "接种成功";
            } else {
                info = "";
            }
        }
        session.setAttribute("info", info);
        out.print("");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }
}
